#ifndef STRAY_RESOURCE_FILE_CACHE_H
#define STRAY_RESOURCE_FILE_CACHE_H

#include <Common.h>
#include <String\String.h>
#include <Container\Map.h>
#include <Container\List.h>
#include <Thread\Mutex.h>

#include "ResourceFile.h"
#include "ResourceFileFactory.h"

namespace Stray {
namespace Resource {

class ResourceFileCache
{
public:
	ResourceFileCache(size_t cacheSize);
	ResFilePtr getFile(const FileID& fileName);
	void flush();
private:
	ResFilePtr find(const FileID& fileName);
	ResFilePtr load(const FileID& fileName);
	void update(const ResFilePtr& spResFile);
	void free(const ResFilePtr& spResFile);
	void freeOneResFile();
private:
	typedef Stray::HashMap<FileID, ResFilePtr>::type ResFileMap;
	typedef Stray::List<ResFilePtr>::type LRUResFileList;

	size_t cacheSize_;
	size_t usedSize_;
	ResFileMap resFileMap_;
	LRUResFileList lruResFileList_;
	ResourceFileFactory factory_;
};

}
}

#endif